//
//  AUEssenceTopicToolbar.swift
//  Alamofire
//
//  Created by Miss_Special on 2018/4/27.
//

import UIKit

class AUEssenceTopicToolbar: UIView {
    
    // bundle
    fileprivate var bundle: Bundle {
        get {
            return Bundle.init(for: type(of: self))
        }
    }
    
    fileprivate lazy var ding_button: UIButton = {
        return createButton(imageName: "mainCellDing", title: "顶")
    }()
    
    fileprivate lazy var cai_button: UIButton = {
        return createButton(imageName: "mainCellCai", title: "踩")
    }()
    
    fileprivate lazy var share_button: UIButton = {
        return createButton(imageName: "mainCellShare", title: "分享")
    }()
    
    fileprivate lazy var comment_button: UIButton = {
        return createButton(imageName: "mainCellComment", title: "分享")
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = UIColor.white
        
        addSubview(ding_button)
        addSubview(cai_button)
        addSubview(share_button)
        addSubview(comment_button)
        
        ding_button.snp.makeConstraints { (make) in
            make.top.left.bottom.equalToSuperview()
        }
        cai_button.snp.makeConstraints { (make) in
            make.top.bottom.equalToSuperview()
            make.left.equalTo(ding_button.snp.right)
            make.width.equalTo(ding_button)
        }
        share_button.snp.makeConstraints { (make) in
            make.top.bottom.equalToSuperview()
            make.left.equalTo(cai_button.snp.right)
            make.width.equalTo(ding_button)
        }
        comment_button.snp.makeConstraints { (make) in
            make.top.bottom.right.equalToSuperview()
            make.left.equalTo(share_button.snp.right)
            make.width.equalTo(ding_button)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

extension AUEssenceTopicToolbar {
    fileprivate func createButton(imageName: String, title: String) -> UIButton {
        // create
        let button = UIButton()
        
        // image
        let normalImageName = "\(imageName)@2x"
        let highlightedImageName = "\(imageName)Click@2x"
        button.setImage(AUHomeModule.imageFromBundle(bundle: self.bundle, imageName: normalImageName), for: .normal)
        button.setImage(AUHomeModule.imageFromBundle(bundle: self.bundle, imageName: highlightedImageName), for: .highlighted)
        button.setImage(AUHomeModule.imageFromBundle(bundle: self.bundle, imageName: highlightedImageName), for: .selected)
        // title
        button.setTitle(title, for: .normal)
        button.setTitleColor(common_textColor_gray, for: .normal)
        button.setTitleColor(UIColor(au_rgbColor: 240, g: 110, b: 120), for: .highlighted)
        button.setTitleColor(UIColor(au_rgbColor: 240, g: 110, b: 120), for: .selected)
        button.titleLabel?.font = UIFont.au_scaledFont(size: 15)
        button.titleEdgeInsets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 0)
        button.sizeToFit()
        
        return button
    }
}
